function fake_click (obj) {
  var ev = document.createEvent("MouseEvents");
  ev.initMouseEvent(
    "click", true, false, window, 0, 0, 0, 0, 0
    , false, false, false, false, 0, null
  );
  obj.dispatchEvent(ev);
}
export function download (name, data) {
  var urlObject = window.URL || window.webkitURL || window;

  var downloadData = new Blob([data]);

  var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
  save_link.href = urlObject.createObjectURL(downloadData);
  save_link.download = name;
  fake_click(save_link);
}
export function downloadHtml(name, data) {
  var html_tmp = "<!DOCTYPE html>"+
    "<html>"+
    "<head>"+
    "</head>"+
    "<body>"+
    "<div>"+data+"</div>"+
    "</body>"+
    "</html>"
  var urlObject = window.URL || window.webkitURL || window;

  var downloadData = new Blob([html_tmp]);

  var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
  save_link.href = urlObject.createObjectURL(downloadData);
  save_link.download = name;
  fake_click(save_link);
}
// 调用方法
// download("itdouzi.txt","使用js下载www.itdouzi.com");
